// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import store from './vuex/store'
import router from './routes'
import FastClick from 'fastclick'
import App from './App'
// import VConsole from 'vconsole'

import { TransferDomDirective as LoadingPlugin, AjaxPlugin, WechatPlugin, ToastPlugin, ConfirmPlugin, AlertPlugin,
  querystring } from 'vux'

// import {VmCollapse, VmCollapseItem} from 'vue-multiple-collapse'

// import productApi from './api/product'

Vue.use(AjaxPlugin)
Vue.use(LoadingPlugin)
Vue.use(WechatPlugin)
Vue.use(AlertPlugin)
Vue.use(ToastPlugin)
Vue.use(ConfirmPlugin)

FastClick.attach(document.body)

Vue.config.productionTip = false

// router.beforeEach(function (to, from, next) {
//   Vue.$vux.loading.show({text: '数据加载中'})
//   next()
// })

/*eslint-disable*/
// router.afterEach(function (to) {
//   document.title = to.meta.title || ''
//   Vue.$vux.loading.hide()

// })

// let vConsole = new VConsole();

// 重点
let searchParam = querystring.parse(location.search)
let shareOpenId = searchParam.shareOpenId

// 重定向后出错, 可能出现 url?shareOpenId=xxx&shareOpenId=xxx的情况
// 此时searchParam.searchParam是个数组
if (shareOpenId instanceof Array) shareOpenId = shareOpenId[0]

// Add a request interceptor
Vue.http.interceptors.request.use(function (config) {

  return config
}, function (error) {
  return Promise.reject(error)
})

// Add a response interceptor
Vue.http.interceptors.response.use(function (response) {
  Vue.$vux.loading.hide()

  return response
}, function (error) {
  Vue.$vux.loading.hide()

  Vue.$vux.toast.show({
    text: '网络异常',
    position: 'middle',
    type: 'cancel'
  })

  return Promise.reject(error)
})

/* eslint-disable no-new */
window.vm = new Vue({
  store,
  router,
  render: h => h(App),
  created () {
  }
}).$mount('#app-box')


